using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq.Expressions;
using System.Web;
using System.Web.Mvc;
using System.Web.Mvc.Ajax;
using Winter.BackEnd.Models.Domain;
using Winter.BackEnd.Models.GoogleMaps;

namespace Winter.BackEnd.Controllers
{
    public class ClassesController : ApplicationController
    {
        //
        // GET: /Classes/

        public ActionResult Index()
        {
            return View();
        }

        public ActionResult Details(int? id)
        {
            Class classDetails = Repository.CurrentDataContext.Classes.SingleOrDefault(c => c.ID == id);
            var Details = new
            {
                ClassName = classDetails.Subject.Name,
                StartTime = classDetails.ClassStartTime,
                EndTime = classDetails.ClassEndTime,
                LectureRoom = classDetails.LetureRoom,
                Building = classDetails.Builging.BuildingName,
                LectureNumber = classDetails.ClassNumber,
                TeacherName = classDetails.Teacher.FullName
            };
            Array.ForEach(Details.GetType().GetProperties().ToArray(), (p) => { ViewData[p.Name] = p.GetValue(Details, null); });

            return View();
        }

        public ActionResult Map(string buildingName)
        {
            var mapRepository = new MapRepository();
            var map = mapRepository.GetById(buildingName);
            return Json(map);
        }
    }
}
